package com.yanqu.road.server.cmd.crossunion;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.task.args.union.UnionRechargeUserArgs;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.crossunion.activity.CrossUnionActivityRankDataProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.union.CrossUnionActivityDataMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.util.List;

@Cmd(code = CrossProtocol.C_CROSS_UNION_RECHARGE_ACTIVITY_CHANGE,desc = "")
public class CrossUnionRechargeActivityChangeCmd extends CrossCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossUnionActivityRankDataProto.CrossUnionRechargeChangeMsg req = CrossUnionActivityRankDataProto.CrossUnionRechargeChangeMsg.parseFrom(packet.getBytes());
        int activityId = req.getActivityId();
        List<Long> serverList = req.getServerListList();
        CrossUnionActivityRankDataProto.UnionRechargeArgMsg arg = req.getArg();
        int type = arg.getType();
        int addValue = arg.getAddValue();
        String unionId = arg.getUnionId();
        long userId = arg.getUserId();
        if (req.hasUserBaseInfo()) {
            PlayerProto.PlayerBaseTempMsg userBaseInfo = req.getUserBaseInfo();
            UserBaseInfo baseInfoa = PlayerBasePb.parseBaseUserInfo(userBaseInfo);
            CrossUserMgr.updateUserBaseInfo(userId, baseInfoa);
        }
        UnionRechargeUserArgs args = new UnionRechargeUserArgs(type,addValue,unionId,userId);
        args.setGetReward(arg.getGetReward());
        args.setConditionId(arg.getConditionId());
        CrossUnionActivityDataMgr.changeUnionRechargeData(activityId, args, serverList);
    }

    @Override
    public void sendData() {

    }
}
